Shader "Unlit/S_Lambert Gradient Add DIss"
{
    Properties
    {
        _MainColor("Color", Color) = (1,1,1,1)
        _MainTex ("Texture", 2D) = "white" {}
        _Noise ("Noise", 2D) = "white" {}
        _AlphaClip("Alpha Clip", Range(0, 1)) = 0
        _OutlineColor("Outline Color", Color) = (1,1,1,1)
        _OutlineScale("Outline Scale", Range(0, 0.1)) = 0
    }
    SubShader
    {
        Tags {"LightMode" = "UniversalForward"}
        LOD 100
        
        Pass
        {
            Tags { "RenderType"="Opaque" "Queue" = "Geometry"}
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float3 normal : NORMAL;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
                float3 lightDirWS : TEXCOORD1;
                float3 normalWS : TEXCOORD2;
            };

            sampler2D _MainTex;
            sampler2D _Noise;
            fixed4 _MainColor;
            fixed _AlphaClip;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.lightDirWS = UnityWorldSpaceLightDir(mul(unity_ObjectToWorld, v.vertex).xyz);
                o.normalWS = UnityObjectToWorldNormal(v.normal);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed lambertH = dot(normalize(i.normalWS), normalize(i.lightDirWS)) * 0.5 + 0.5;
                fixed4 col = tex2D(_MainTex, lambertH.xx);
                col *= _MainColor;

                fixed4 noise = tex2D(_Noise, i.uv);

                clip(noise.g - _AlphaClip);
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
        Pass
        {
            Name "Outline"
            Tags { "LightMode" = "SRPDefaultUnlit"}

            Cull Front

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

            fixed _OutlineScale;
            fixed4 _OutlineColor;

            v2f vert (appdata v)
            {
                v2f o;
                v.vertex.xyz += _OutlineScale * v.normal;
                o.vertex = UnityObjectToClipPos(v.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = _OutlineColor;
                return col;
            }
            ENDCG
        }
        
    }
}
